{php include wl_template('common/header');}
<ul class="nav nav-tabs">
	<li class="active"><a href="javascript:;">红包设置</a></li>
</ul>
<div class="app-content">
	<div class="app-form">
	<div class="panel panel-default">
		<form  action="" method="post" class="form-horizontal form form-validate">
			  <div class="panel panel-default" >
				<div class="panel-heading">红包信息</div>
				<div class="panel-body">
					<div class="form-group">
						<label class="col-sm-2 control-label">红包活动标题<span class="must-fill">*</span></label>
						<div class="col-sm-9">
							<input type="text" name="redpack[title]" maxlength="8" required autocomplete="off" class="form-control" value="{$redpack['title']}">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">红包页面</label>
						<div class="col-sm-9">
							<select name="redpack[diypageid]" class="form-control chosen-select">
								<option value="" {if empty($redpack['diypageid'])}selected="selected"{/if}>请选择红包页面</option>
								{loop $diypagelist $page}
								<option value="{$page['id']}" {if $redpack['diypageid'] == $page['id']}selected="selected"{/if}>{$page['name']}</option>
								{/loop}
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">红包海报</label>
						<div class="col-sm-9">
							<select name="redpack[posterid]" class="form-control chosen-select">
								<option value="" {if empty($redpack['posterid'])}selected="selected"{/if}>请选择红包海报</option>
								{loop $diyposterlist $poster}
								<option value="{$poster['id']}" {if $redpack['posterid'] == $poster['id']}selected="selected"{/if}>{$poster['title']}</option>
								{/loop}
							</select>
						</div>
					</div>
					<div class="form-group" >
						<label class="col-sm-2 control-label">红包金额</label>
						<div class="col-sm-9">
							<div class="input-group">
								<span class="input-group-addon">直接领取金额￥</span>
								<input type="number" name="redpack[onemoney]" class="form-control" value="{$redpack['onemoney']}" />
							</div>
							<div class="help-block">红包金额填入正数，填0或者不填即没有对应红包奖励，最多保留两位小数。</div>
						</div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label must">分享奖励</label>
					    <div class="col-sm-9">
					        <div id="datas">
					            {if empty($sharemoneys)}
					            {php include wl_template('store/sharemoney');}
					            {else}
					            {loop $sharemoneys $ba}
					            {php include wl_template('store/sharemoney');}
					            {/loop}
					            {/if}
					        </div>
					        <span class="help-block">分享的人数达到要求，即可领取对应红包金额，最多设置五个阶段奖励。</span>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label"></label>
					    <div class="col-sm-9">
					        <a class="btn btn-info btn-add-type" id="addtype" href="javascript:;" onclick="addType();">
					            <i class="fa fa-plus" title=""></i>增加一段奖励
					        </a>
					    </div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">领取区域<span class="must-fill">*</span></label>
						<div class="col-sm-9">
							<div class="row row-fix js-address-selector">
								<div class="col-md-4">
									<select name="redpack[provinceid]" class="form-control tpl-province" required data-value="{$redpack['provinceid']}"></select>
								</div>
								<div class="col-md-4">
									<select name="redpack[areaid]" class="form-control tpl-city" required data-value="{$redpack['areaid']}"></select>
								</div>
								<div class="col-md-4">
									<select name="redpack[distid]" data-value="{$redpack['distid']}" class="form-control tpl-district"></select>
								</div>
							</div>
						</div>
					</div>
					
		            <div class="form-group">
		                <label class="col-sm-2 control-label">活动状态 </label>
		                <div class="col-sm-9">
		                    <label class="radio-inline"><input type="radio" name="redpack[status]" value="1" {if $redpack['status']==1}checked="checked"{/if}> 开启</label>
		                    <label class="radio-inline"><input type="radio" name="redpack[status]" value="0" {if $redpack['status']!=1}checked="checked"{/if}> 关闭</label>
		                </div>
		            </div>
		            <div class="form-group">
		                <label class="col-sm-2 control-label"></label>
		                <div class="col-sm-9">
		                    <input type="submit" value="提交" class="btn btn-primary min-width">
		                    <input type="hidden" name="token" value="{$_W['token']}">
		                    <input type="hidden" name="id" value="{$_GPC['id']}">
		                    <input type="button" name="back" onclick="history.back()" value="返回列表" class="btn btn-default min-width">
		                </div>
		            </div>
	            </div>
		    </div>
		</form>
	</div>
	</div>
</div>

<script type="text/javascript">
	require(["jquery", "{$_W['siteroot']}addons/{MODULE_NAME}/web/resource/js/district.min.js"], function($, dis){
		$(".js-address-selector").each(function(){
			var elements = {};
			elements.province = $(this).find(".tpl-province")[0];
			elements.city = $(this).find(".tpl-city")[0];
			elements.district = $(this).find(".tpl-district")[0];
			var values = {};
			values.province = $(elements.province).data("value");
			values.city = $(elements.city).data("value");
			values.district = $(elements.district).data("value");
			dis.render(elements, values, {withTitle: true, code : true}, {$allArea});
		});
	});
	
	
	var kw = "{$giftnum}";
	function addType() {
	    $(".btn-add-type").button("loading");
	    $.ajax({
	        url: "{php echo web_url('store/comment/sharemoney')}&kw="+kw,
	        cache: false
	    }).done(function (html) {
	        $(".btn-add-type").button("reset");
	        $("#datas").append(html);
	    });
	    kw++;
	    if(kw >= 5){
	        $("#addtype").hide();
	    }
	}
	
	function removes(asd){
	    $(asd).closest('.data-item').remove();
	    kw--;
	    $("#addtype").show();
	}
	
</script>

{php include wl_template('common/footer');}